<template>
  <div class="home-new">
    <HomePanel title="人气推荐" subTitle="人气爆款 不容错过">
      <!-- 右上角插槽 -->
      <!-- <template #right></template> -->
      <!-- 面板内容 -->
      <div ref="target" style="position:relative;height:426px;">
        <transition name="fade">
          <ul  ref="target" class="goods-list" v-if="goods.length">
            <li v-for="item in goods" :key="item.id">
              <router-link :to="`/product/${item.id}`">
                <img :src="item.picture" alt="">
                <p class="name ellipsis">{{item.title}}</p>
                <p class="alt">{{item.alt}}</p>
              </router-link>
            </li>
          </ul>
          <HomeSkeleton v-else></HomeSkeleton>
        </transition>
      </div>
    </HomePanel>
  </div>
</template>

<script>

import HomePanel from './home-panel.vue'
import { findHot } from '@/api/home'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks'
export default {
  name: 'HomeHot',
  components: {
    HomePanel,
    HomeSkeleton
  },
  setup () {
    /* const goods = ref([])
    findHot().then(data => {
      goods.value = data.result
    }) */
    // 懒加载
    // 1.target 绑定一个监听对象 最好是DOM
    // 2.传入APi接口 内部获取调用 返回的是响应数据
    const { result, target } = useLazyData(findHot)
    return { goods: result, target }
  }
}
</script>

<style lang="less" scoped>
.goods-list{
  display:flex;
  justify-content: space-between;
  height:406px;
  li {
    width: 306px;
    height: 406px;
    background: #fdfdfd;
    .hoverShadow();
    img{
      width: 306px;
      height: 306px;
    }
    p{
      font-size: 22px;
      padding:12px 30px 0 30px;
      text-align: center;
    }
    .alt{
      color: #999;
      font-size: 18px;
    }
  }
}
.fade{
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity .5s .2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}
</style>
